class Hello
  def howdy
    greeting = 'Hello, Ruby!'
    puts greeting
  end
end

# P33
puts `clear` 


v1 = 1
class MyClass
  puts "#{__LINE__}--#{self}"
  puts local_variables.to_s # [:v2]
  v2 = 2
  
  def my_method
    v3=3
    puts "#{__LINE__}--#{self}--v3_id: #{v3.object_id()}"
    local_variables # [:v3] 
  end
  puts local_variables.to_s # [:v2]
end

puts "#{__LINE__}--#{self}"
obj = MyClass.new
# [:v3] 
puts obj.my_method.to_s
puts MyClass.new.my_method.to_s
# [:v1, :obj]
puts local_variables.to_s

=begin 
  14--MyClass
  [:v2]
  [:v2]
  26--main
  20--#<MyClass:0x00007476979a5588>--v3_id: 7
  [:v3]
  20--#<MyClass:0x00007476979a52b8>--v3_id: 7
  [:v3]
  [:v1, :obj]
=end

puts `clear` 

@var1 = 1
$var2 = 2

def fn1
  puts @var1 # 1
  puts $var2 # 2

  puts self # main
end
puts self # main
fn1

puts `clear` 

class Hi
  puts self # Hi
end

puts `clear` 

my_var = "Success"

MyClass02 = Class.new do
  puts "#{my_var} in the class definition!"

  define_method :my_method do
    "#{my_var} in the method"
  end
end

puts MyClass02.new.my_method

puts `clear` 


def define_methods
  shared = 0
  Kernel.send :define_method, :counter do
    shared
  end

  Kernel.send :define_method, :inc do |x|
    shared += x
  end
end

define_methods

puts counter # 0
inc(4) 
puts counter # 4

puts `clear` 


if false
  a01 = 1
end
puts a01==nil # true

puts `clear` 


def fn02
  if false
    a02 = 2
  end
  puts a02 == nil # true
end
fn02

puts `clear` 

class HelloClass
end

def fn03
  var3 = 3

  HelloClass.send :define_method, :a_method do
    var4 =4
    puts local_variables.to_s # [:var4, :var3]
  end

  HelloClass.send :define_method, :a_method02 do
    var3 += 1
    puts var3 # 4
  end
end

fn03
HelloClass.new.a_method
HelloClass.new.a_method02

puts `clear` 

var5 = 5
var6 = 6

1.times do |i; var5,var6|
  puts i
  var5 = 50
  var6 = 60
end

puts var5,var6 # 5 6